package com.dbh.company.buildbook.task;

import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONUtil;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.sax.handler.RowHandler;

import java.util.ArrayList;
import java.util.List;

public class Allot2 {


    public static void main(String[] args) {
        String cookie = "crosSdkDT2019DeviceId=odwtm9--66kz4w-k1wyidbaht2ojs9-ze4kcm0ps; wx_device_id=7SI4QsyxKMshz4hTG40ZXEZsG_Bpf05KV9R0q1ZjZq8=; _ga=GA1.2.380892006.1727062184; lfrc_=7460d006-31bb-4a39-b5fd-ee9f8ac3968c; ke_uuid=49cd228384084e3af2bbd5a1800bd09b; __xsptplus788=788.1.1734335232.1734335232.1%234%7C%7C%7C%7C%7C%23%23%23; ftkrc_=5eff8388-af0b-4522-8d5c-69224676c69a; lianjia_b_token=2.0014c5c24f81542662056c7cfd5ec3d442; _ga_F0DQ6TTSVW=GS1.2.1737360623.11.0.1737360623.60.0.0; Hm_lvt_b160d5571570fd63c347b9d4ab5ca610=1739844359; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%2219154f080932b0-03707230c6e83-4c657b58-1821369-19154f0809413d3%22%2C%22%24device_id%22%3A%2219154f080932b0-03707230c6e83-4c657b58-1821369-19154f0809413d3%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E7%9B%B4%E6%8E%A5%E6%B5%81%E9%87%8F%22%2C%22%24latest_referrer%22%3A%22%22%2C%22%24latest_referrer_host%22%3A%22%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC_%E7%9B%B4%E6%8E%A5%E6%89%93%E5%BC%80%22%2C%22%24latest_utm_source%22%3A%22biying%22%2C%22%24latest_utm_medium%22%3A%22pinzhuan%22%2C%22%24latest_utm_campaign%22%3A%22wymoren%22%2C%22%24latest_utm_content%22%3A%22biaotimiaoshu%22%2C%22%24latest_utm_term%22%3A%22biaoti%22%7D%7D; ztt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhX2NsaWVudCIsImV4cCI6MTc0NDE2MzM2MywianRpIjoiRUMrUlVTQ3FWUmduUzgrNXI1Wko1UT09IiwiaWF0IjoxNzQ0MDc2OTYzLCJpc3MiOiI3NTc1ZWM5NmZiZjM0ZWZjYmFiNDViNGNjN2QyYmU3YiIsInIiOiJ7XCJpXCI6XCIxMC4zNi4xOTQuOTVcIixcInVcIjpcIjEwMDAwMDAwMjkxMzg0OThcIixcInNcIjpcIlNULTE3MzgzMTQ2LXdFWmZERnZFSGNidDcwU2EzMldOQlJoUFktYy1rZS5jb21cIixcImFcIjoxLFwiZVwiOjE3NDQxNjMzNjMsXCJsXCI6LTEsXCJkXCI6MCxcImVpXCI6XCJcIixcImlpXCI6XCIxMC4zNi4xOTQuOTVcIn0ifQ.r3BDNVQfpYDj4RWILlXEpclB_0E7mJvsKMV860HGTsI; family_prod=2.0111a9beb284385a9f0001cb54e37ecdb2886c788b; session_id=122871c6-f698-73ad-afea-2d81c8c40842; lianjia_uuid=1144f52f-321b-4243-960c-92344d4382c4; lianjia_ssid=b2527dc4-0f81-46d9-8a73-db31ba2d7a6a; login_ucid=1000000026033077; security_ticket=mKhii3xePZtjgTimDRNcrgn+3wnS0sAOz/blQxmrJs2GkfuMWVDAo8wfhxfqkTnz6y8fVYaNg/aEXXkQUA4k0mys8dGttwdMiwtubu6frQqXqhQ2U8oLcnWuTehhIY2Rk8NbcpYNaC7ntMO6ubhfpw6bjZZtNtKU95wrG6Et15w=; buildinghouse_login_user=2.0111a9beb284e8ff680001cb5481b7497f8ac98dfb";
        String excelPath = "D:\\data\\Documents\\WXWork\\1688849989768054\\Cache\\File\\2025-04\\苏州选盘终版-0408-1356.xlsx";

        // 使用自定义的RowHandler来处理每一行
        RowHandler rowHandler = new RowHandler() {
            @Override
            public void handle(int sheetIndex, long rowIndex, List<Object> rowlist) {
                // 处理每一行的数据
                if (rowIndex == 0) {
                    // 跳过标题行
                    return;
                }

                // 假设列的顺序是已知的
                String resblockId = Convert.toStr(rowlist.get(3));
//                String ucCode = Convert.toStr(rowlist.get(1));
//                String ucid = String.format("1%015d", Long.parseLong(ucCode));

                String ucid = "3000260000001301";
                // 你的业务逻辑
                String body = HttpRequest.get("https://buildinghouse.ke.com/admin/task/getUser?ucid=" + ucid)
                        .cookie(cookie)
                        .execute().body();
                String jsonStr = JSONUtil.toJsonStr(body);
                Object o = JSONUtil.parseObj(jsonStr).get("data");
                String str = Convert.toStr(JSONUtil.parseObj(o).get("displayName"));
                System.out.println(str);

                ArrayList<String> selectedCollectTaskList = ListUtil.toList("modelCollectTask");
                AllotTaskParam allotTaskParam = AllotTaskParam.builder()
                        .selectedCollectTask(selectedCollectTaskList)
                        .single(1)
                        .resblockIdList(ListUtil.toList(Long.parseLong(resblockId)))
                        .modelCollectUser(Convert.toLong(ucid))
                        .modelCollectUserName(str)
                        .modelCollectStartTime("2025-03-28")
                        .modelCollectEndTime("2025-05-30")
                        .build();
                System.out.println(JSONUtil.toJsonStr(allotTaskParam));

                 String resp = HttpRequest.post("https://buildinghouse.ke.com/admin/task/allot")
                        .cookie(cookie)
                        .body(JSONUtil.toJsonStr(allotTaskParam))
                        .execute().body();
                System.out.println(resp);
            }
        };

        // 使用SAX方式读取Excel
        ExcelUtil.readBySax(excelPath, -1, rowHandler);
    }
}
